#include<stdio.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
    char* argv[4] = {"ls","-a","-l",NULL};
    pid_t id = fork();
    if(id < 0)
    {
      perror("fork :");
      exit(1);
    }
    else if(id == 0) //child
    {
      int count = 5;
      while(count--)
      {
        printf("I am child .... I am running\n");
        sleep(1);
      }
      //进程替换
      //execl("/usr/bin/ls","ls","-a","-l",NULL);
      //execvp("ls",argv);
      //execlp("ls","ls","-a","-l",NULL);
      execl("/usr/bin/python","python","test.py",NULL);
      exit(2);//进程替换成功是不会返回的，来到这里，说明进程替换失败
    }
    else{
      //parent
      int status = 0;
      while(waitpid(id,&status,WNOHANG) == 0)
      {
        printf("parent ruunning .....\n");
        sleep(1);
      }
      //子进程退出
      printf("exitcode:%d exitSignal:%d\n",(status >> 8)&0xff,status & 0x7f);
    }
    return 0;
}
